package ModelLag;
import java.util.ArrayList;


/**
 * The DVDContainer class holds up to several object of the type DVD.
 * 
 * @author (Lackshan, Mikkel, Nick, patrick, Simon, Yousef) 
 * @project (Tema design)
 * @version (2014.11.04)
 */
public class DVDContainer
{
    private static DVDContainer instance = null;
    private ArrayList<DVD> dvds;

    /**
     * Constructor for objects of class DVDContainer
     */
    private DVDContainer(){
        dvds = new ArrayList<DVD>();
    }
    
    /**
     * Returns an instance of DVDContainer
     * 
     * @return an instance of DVDContainer
     */ 
    public static DVDContainer getInstance(){
        if(instance == null){
            instance = new DVDContainer();
        }
        return instance;
    }
    
    /**
     * Adds a Person object to the persons Arraylist in the PersonContainer class
     * 
     * @param p is the user input for a specific person
     */
    public void addDVD(DVD d){
        dvds.add(d);
    }
    
    /**
     * Finds a specified DVD Object using that DVDs barcode
     * 
     * @param b the barcode of the DVD
     * @return the DVD object if found. Else null
     */
    public DVD findDVD(String barcode){
        int i = 0;
        boolean found = false;
        DVD returnDVD = null;
        while (!found && i<dvds.size()){
            DVD d = dvds.get(i);
            if (barcode.equalsIgnoreCase(d.getBarcode())){
                found = true; 
                returnDVD = d;
            }
               i++;      
        }      
        return returnDVD;
    }
    
    /**
     * Retun a DVD wich contains a copy with the specific serialNumber
     * 
     * @param serialNumber the serialNumber of the Copy
     * @return the DVD object if found. Else null.
     */
    public DVD findDVDfromCopy(String serialNumber){
        int i = 0;
        boolean found = false;
        DVD returnDVD = null;
        while (!found && i<=dvds.size()){
            DVD d = dvds.get(i);
            if (d.containsCopy(serialNumber)){
                found = true;
                returnDVD = d;
            }
            i++;     
        }      
        return returnDVD;
    }
    
    /**
     * Delete DVD from collection
     * 
     * @param barcode the barcode of the DVD to delete
     */
    public void deleteDVD(String barcode){
        DVD d = findDVD(barcode);
        dvds.remove(d);
    }
    
}

